﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;

namespace YArchitech.HVAC
{
	public static class DeleteMarksHelper
	{
		public static List<Element> FilterGroup(List<MarkType> list, Autodesk.Revit.DB.Document doc, ICollection<ElementId> collection)
		{
			List<Element> list2 = new List<Element>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc, collection);
			filteredElementCollector.OfClass(typeof(Group));
			if (!filteredElementCollector.Any<Element>())
			{
				return list2;
			}
			foreach (Element element in filteredElementCollector)
			{
				foreach (MarkType markType in list)
				{
					if (AssociationMarkInfo.IsRightMarkType(element, markType.ToString()))
					{
						list2.Add(element);
						break;
					}
				}
			}
			return list2;
		}

		public static void DeleteFilterGroup(List<MarkType> list, Autodesk.Revit.DB.Document doc, ICollection<ElementId> collection)
		{
			List<Element> list2 = DeleteMarksHelper.FilterGroup(list, doc, collection);
			if (list2.Count < 1)
			{
				return;
			}
			foreach (Element element in list2)
			{
				doc.Delete(element.Id);
			}
		}

		public static List<Element> FilterTags(List<MarkType> list, Autodesk.Revit.DB.Document doc, ICollection<ElementId> collection)
		{
			List<Element> list2 = new List<Element>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc, collection);
			filteredElementCollector.OfClass(typeof(IndependentTag));
			if (!filteredElementCollector.Any<Element>())
			{
				return list2;
			}
			foreach (Element element in filteredElementCollector)
			{
				foreach (MarkType markType in list)
				{
					if (AssociationMarkInfo.IsRightMarkType(element, markType.ToString()))
					{
						list2.Add(element);
						break;
					}
				}
			}
			return list2;
		}

		public static void DeleteFilterTags(List<MarkType> list, Autodesk.Revit.DB.Document doc, ICollection<ElementId> collection)
		{
			List<Element> list2 = DeleteMarksHelper.FilterTags(list, doc, collection);
			if (list2.Count < 1)
			{
				return;
			}
			foreach (Element element in list2)
			{
				doc.Delete(element.Id);
			}
		}
	}
}
